/*
 * @Author: 李家磊
 * @Date: 2022-03-30 08:21:40
 * @LastEditTime: 2022-03-30 14:23:52
 * @LastEditors: 李家磊
 * @Description:
 * @FilePath: /CURD/src/pages/second/second-1/index.tsx
 */

import { PageContainer } from "@ant-design/pro-layout";
import { Button, Layout } from "antd";
import { useState } from "react";
import styles from "./index.less"

const Second1: React.FC<{}> = () => {
  interface treeBaseDate<T> {
    subs?: T[];
    children?: T[];
  }

  const rmsub = <T extends treeBaseDate<T>>(data: T[]) => {
    if (data && data.length > 0) {
      return data.map((row: T) => {
        const temp = row;
        if (row.subs && row.subs.length === 0) {
          temp.subs = undefined;
        }
        temp.subs = rmsub(row.subs || []);
        return temp;
      });
    }
    return data;
  };

  const result = {
    "data":[
      {
        "adminUserId":"1",
        "createTime":"2022-01-13 03:03:31",
        "delFlg":1,
        "deptId":"1",
        "deptName":"统信软件技术有限公司",
        "deptType":1,
        "parentDeptId":"0",
        "salesUnitId":"",
        "salesUnitName":"",
        "subs":[
          {
            "adminUserId":"",
            "createTime":"2022-03-15 10:48:35",
            "delFlg":1,
            "deptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
            "deptName":"行业技术部",
            "deptType":2,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:49:08",
                "delFlg":1,
                "deptId":"cdcf13c10a434b7cbc4738044142e1ec",
                "deptName":"金融售前专案部",
                "deptType":2,
                "parentDeptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:49:26",
                "delFlg":1,
                "deptId":"78f244d4fd364a0c89d2a9ffa1406e12",
                "deptName":"运营商售前专案部",
                "deptType":2,
                "parentDeptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:49:39",
                "delFlg":1,
                "deptId":"6bd9086619e34982ba953eda9bdc4830",
                "deptName":"交通售前专案部",
                "deptType":1,
                "parentDeptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:49:47",
                "delFlg":1,
                "deptId":"1d902d512c4548c6ac1ed06882a58032",
                "deptName":"能源售前专案部",
                "deptType":1,
                "parentDeptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:50:04",
                "delFlg":1,
                "deptId":"3cff7065bf3e448b87c73e2bef0ba9bb",
                "deptName":"行业项目支持部",
                "deptType":1,
                "parentDeptId":"3ee015f4f2464f8bb3c109c5a96c6d15",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              }
            ]
          },
          {
            "adminUserId":"c3f69490470a45c2b52849e061d6319a",
            "createTime":"2022-03-15 10:48:47",
            "delFlg":1,
            "deptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
            "deptName":"区域技术部",
            "deptType":2,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:50:51",
                "delFlg":1,
                "deptId":"996f3ccb6ca34b18920eb4587210dabb",
                "deptName":"华北售前专案部",
                "deptType":1,
                "parentDeptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:51:05",
                "delFlg":1,
                "deptId":"5b142db2a0014295a133312c796705ca",
                "deptName":"华东售前专案部",
                "deptType":1,
                "parentDeptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"3844af2008bb4bc6b2d6ff4ff1d465ca",
                "createTime":"2022-03-15 10:51:43",
                "delFlg":1,
                "deptId":"388caf19688e4280b73c8c3d3cd88c3f",
                "deptName":"华南售前专案部",
                "deptType":2,
                "parentDeptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:51:55",
                "delFlg":1,
                "deptId":"ec0364b93c3145758c6309f2e817e246",
                "deptName":"华西售前专案部",
                "deptType":1,
                "parentDeptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              },
              {
                "adminUserId":"",
                "createTime":"2022-03-15 10:52:29",
                "delFlg":1,
                "deptId":"4f446cf9de1d407cb87d85278ebcf91e",
                "deptName":"区域项目支持部",
                "deptType":1,
                "parentDeptId":"cb4a9f1e9f684b7da1dfa13c91667bf7",
                "salesUnitId":"",
                "salesUnitName":"",
                "subs":[]
              }
            ]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 10:59:45",
            "delFlg":1,
            "deptId":"504164a9ec4744a79da6be93d826035f",
            "deptName":"技术管理部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:03:22",
            "delFlg":1,
            "deptId":"6411abde625145b18fd0aa358f9d36ed",
            "deptName":"金融行业销售部",
            "deptType":3,
            "parentDeptId":"1",
            "salesUnitId":"62c40993-7359-11ec-b6e1-0242ac110002",
            "salesUnitName":"金融",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:03:39",
            "delFlg":1,
            "deptId":"1c51e3abe9244286aeaa16effc839b4c",
            "deptName":"运营商行业销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:03:52",
            "delFlg":1,
            "deptId":"c028f26d6fd945a1b5d52f9a3f15f9fa",
            "deptName":"交通行业销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:04:09",
            "delFlg":1,
            "deptId":"c5b7e7dd9a234a6995eaee992dbc3039",
            "deptName":"电力行业销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:04:17",
            "delFlg":1,
            "deptId":"377d2979138e492991dfc0ffcab58003",
            "deptName":"能源行业销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:04:30",
            "delFlg":1,
            "deptId":"54b315ad86f644739b596e1ad3e700dd",
            "deptName":"华东大区销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:04:45",
            "delFlg":1,
            "deptId":"fca9c628538d4549909df46a2137a85b",
            "deptName":"华西大区销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:04:52",
            "delFlg":1,
            "deptId":"088e23d63acd44e2ad61aff245d5bb55",
            "deptName":"华北大区销售部",
            "deptType":1,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          },
          {
            "adminUserId":"",
            "createTime":"2022-03-15 11:05:00",
            "delFlg":1,
            "deptId":"bcce92f0e16a41c883c4ef7e55d8d81b",
            "deptName":"华南大区销售部",
            "deptType":3,
            "parentDeptId":"1",
            "salesUnitId":"",
            "salesUnitName":"",
            "subs":[]
          }
        ]
      }
    ],
    "message":"ok",
    "status":1,
    "timestamp":1648618950780
  }


  return (
  <PageContainer>
    <Button
      onClick={()=>{
        console.log(rmsub(result.data))
        }
      }
    >
      点击
    </Button>
    <Button
      onClick={()=>{
        console.log(result.data)
      }}
    >
      按钮
    </Button>
  </PageContainer>
  )
}

export default Second1;
